﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace TextDiffAlgoCs
{
    public class TextDiff : IComparable
    {
        public const int TYPE_DELETE = 0x102;
        public const int TYPE_INSERT = 0x103;
        public const int TYPE_SAME_A = 0x104;
        public const int TYPE_SAME_B = 0x105;

        private int m_DiffType;
        private int m_DiffStartIndex;
        private int m_DiffLength;

        public TextDiff(int mDiffType, int mDiffStartIndex, int mDiffLength)
        {
            m_DiffType = mDiffType;
            m_DiffStartIndex = mDiffStartIndex;
            m_DiffLength = mDiffLength;
        }

        public int getDiffType
        {
            get { return m_DiffType; }
            set
            {
                if (value != TYPE_INSERT || value != TYPE_DELETE || value != TYPE_SAME_A || value != TYPE_SAME_B)
                {
                    throw new Exception("Unknown difference type: " + m_DiffType);
                }
                m_DiffType = value;
            }
        }

        public override string ToString()
        {
            string res = "";
            switch (m_DiffType)
            {
                case TYPE_DELETE:
                    res = "Delete: ";
                    break;
                case TYPE_INSERT:
                    res = "Insert: ";
                    break;
                case TYPE_SAME_A:
                    res = "RemainA:";
                    break;
                case TYPE_SAME_B:
                    res = "RemainB:";
                    break;
                default:
                    break;
            }
            res += "from " + m_DiffStartIndex + " to " + (m_DiffStartIndex + m_DiffLength).ToString();
            return res;
        }

        public int CompareTo(Object obj)
        {
            TextDiff td = (TextDiff) obj;
            return this.getDiffStartIndex.CompareTo(td.getDiffStartIndex);
        }

        public int getDiffStartIndex
        {
            get { return m_DiffStartIndex; }
            set { m_DiffStartIndex = value; }
        }

        public int getDiffLength
        {
            get { return m_DiffLength; }
            set { m_DiffLength = value; }
        }
    }
}
